﻿804.唯一摩尔斯密码词
int uniqueMorseRepresentations(char** words, int wordsSize) {
    char* s[26] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };
    int ans = 0;
    char** arr = (char**)malloc(sizeof(char*) * wordsSize);
    for (int i = 0; i < wordsSize; i++)
    {
        char* temp = (char*)malloc(sizeof(char) * 50);
        temp[0] = '\0';
        for (int j = 0; j < strlen(words[i]); j++)
        {
            sprintf(temp + strlen(temp), "%s", s[words[i][j] - 'a']);
        }
        arr[i] = temp;
        int count = 0;
        for (int k = 0; k < i; k++)
        {
            if (strcmp(temp, arr[k]) != 0)
            {
                count++;
            }
        }
        if (count == i)
        {
            ans++;
        }
    }
    return ans;
}

806.写字符串需要的行数
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* numberOfLines(int* widths, int widthsSize, char* s, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * 2);
    ans[0] = 1;
    ans[1] = 0;
    *returnSize = 2;

    int sum = 0;
    for (int i = 0; i < strlen(s); i++)
    {
        sum += widths[s[i] - 'a'];
        if (sum > 100)
        {
            i--;
            ans[0]++;
            sum = 0;
        }
    }
    ans[1] = sum;
    return ans;
}

812.最大三角形面积
double largestTriangleArea(int** points, int pointsSize, int* pointsColSize) {
    double ans = 0;
    for (int i = 0; i < pointsSize - 2; i++)
    {
        for (int j = i + 1; j < pointsSize - 1; j++)
        {
            for (int k = j + 1; k < pointsSize; k++)
            {
                double p = (sqrt((points[i][0] - points[j][0]) * (points[i][0] - points[j][0]) + (points[i][1] - points[j][1]) * (points[i][1] - points[j][1])) + sqrt((points[k][0] - points[j][0]) * (points[k][0] - points[j][0]) + (points[k][1] - points[j][1]) * (points[k][1] - points[j][1])) + sqrt((points[i][0] - points[k][0]) * (points[i][0] - points[k][0]) + (points[i][1] - points[k][1]) * (points[i][1] - points[k][1]))) / 2;
                double s = sqrt(p * (p - sqrt((points[i][0] - points[j][0]) * (points[i][0] - points[j][0]) + (points[i][1] - points[j][1]) * (points[i][1] - points[j][1]))) * (p - sqrt((points[k][0] - points[j][0]) * (points[k][0] - points[j][0]) + (points[k][1] - points[j][1]) * (points[k][1] - points[j][1]))) * (p - sqrt((points[i][0] - points[k][0]) * (points[i][0] - points[k][0]) + (points[i][1] - points[k][1]) * (points[i][1] - points[k][1]))));
                if (s > ans)
                {
                    ans = s;
                }
            }
        }
    }
    return ans;
}

821.字符的最短距离
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* shortestToChar(char* s, char c, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * strlen(s));
    *returnSize = strlen(s);

    int l = 0, r = 0;
    while (s[l] != c)
    {
        l++;
    }
    r = l + 1;
    while (s[r] != c && r < strlen(s))
    {
        r++;
    }

    if (r == strlen(s))
    {
        for (int i = 0; i < strlen(s); i++)
        {
            ans[i] = abs(l - i);
        }
    }
    else
    {
        for (int i = 0; i < strlen(s); i++)
        {
            if (i == r)
            {
                ans[i] = 0;
                l = r;
                r = l + 1;
                while (s[r] != c && r < strlen(s))
                {
                    r++;
                }
                if (r == strlen(s))
                {
                    r = l;
                }
                continue;
            }
            ans[i] = abs(i - l) < abs(i - r) ? abs(i - l) : abs(i - r);
        }
    }

    return ans;
}

2974.最小数字游戏
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
    int* numberGame(int* nums, int numsSize, int* returnSize) {
    for (int i = 0; i < numsSize - 1; i++)
    {
        for (int j = 0; j < numsSize - i - 1; j++)
        {
            if (nums[j] > nums[j + 1])
            {
                int temp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = temp;
            }
        }
    }

    int* arr = (int*)malloc(sizeof(int) * numsSize);
    *returnSize = 0;
    for (int i = 0; i < numsSize; i += 2)
    {
        arr[(*returnSize)++] = nums[i + 1];
        arr[(*returnSize)++] = nums[i];
    }
    return arr;
}

----------------------------------------------------------------------------------------
（力扣）189.轮转数组
void swap(int* arr, int l, int r) {
    while (l < r)
    {
        int temp = arr[l];
        arr[l] = arr[r];
        arr[r] = temp;
        l++;
        r--;
    }
}
void rotate(int* nums, int numsSize, int k) {
    k = k % numsSize;
    swap(nums, 0, numsSize - k - 1);
    swap(nums, numsSize - k, numsSize - 1);
    swap(nums, 0, numsSize - 1);
}